<template>
    <block v-if="scene == 1154">
    	<pyq-open-chunk></pyq-open-chunk>
    </block>
    <block v-else>
        <view class="page bg bg-fff">
            <view class="item flex">
                <text>公积金可贷金额</text>
                <text class="moneyBox">{{ loanAmount }}万</text>
            </view>
            <!-- <view class="item flex">
                <text>缴纳住房公积金可贷金额</text>
                <text class="moneyBox">{{ loanAmount }}万</text>
            </view> -->
            <!-- <view class="item flex">
                <text>缴纳补充住房公积金可贷金额</text>
                <text class="moneyBox">{{houseIndex == 1?(familyIndex==1?'10':'20'):(familyIndex==1?'10':'20')}}万</text>
            </view>
            <view class="item flex">
                <text>可贷金额合计</text>
                <text class="moneyBox">{{houseIndex == 1?(familyIndex==1?'60':'120'):(familyIndex==1?'50':'100')}}万</text>
            </view>
            <view class="item flex">
                <text>贷款利率</text>
                <text class="moneyBox">{{houseIndex == 1?'基准利率':'基准利率上浮10%'}}</text>
            </view> -->
            
            <view class="submitBtn bg-theme col-fff font15" @click="againCalc">重新计算</view>
            <view class="tips font12">
                注：
                <block v-if="houseIndex == 1">
                    <view class="top-5">1.住房建筑面积在90平方米（含）以下的，贷款首付款比例不得低于20%；</view>
                    <view class="top-5">2.住房建筑面积在90平方米以上的，贷款首付款比例不得低于30%；</view>
                </block>
                <block v-else>
                    <view class="top-5">1.购买第二套改善型住房的，贷款首付款比例不得低于35%；</view>
                    <view class="top-5">2.购买第二套改善型住房在自贸区临港新片区以及嘉定、青浦、松江、奉贤、宝山、金山6个行政区的，贷款首付款比例不得低于30%；</view>
                </block>
                <view class="top-5">3.购买二星级及以上新建绿色建筑住房公积金(含补充)最高贷款额度上浮15%。</view>
                <view class="top-5">4.本计算结果仅供参考。</view>
            </view>
        </view>
    </block>
</template>

<script>
    import { mapState } from 'pinia';
    import { useConfigStore, useUserInfoStore } from '@/store/index';
    import { isBoolean } from '@/common/common';
    export default {
        data() {
            return {
                houseIndex: 1,
                familyIndex: 1,
                isGreenBuild: false,
                loanAmount: 0
            }
        },
        computed:{
            ...mapState(useConfigStore, ['scene']),
            ...mapState(useUserInfoStore, ['userInfo']),
        },
        onShareAppMessage(res) {
            return {
                title: `公积金贷款额度计算器，点击查看详情`,
                path: `/pages/tools/calculator/accumulate-limit-query?puid=${this.userInfo.id}&share=true`,
            }
        },
        
        onShareTimeline() {
            return {
                title: `公积金贷款额度计算器，点击查看详情`,
                query: `puid=${this.userInfo.id}&share=true`
            }
        },
        
        onLoad(options) {
            //朋友圈进入小程序快照场景
            if(this.scene == 1154) return;
            
            let { houseIndex, familyIndex, isGreenBuilding } = options;
            this.houseIndex = houseIndex;
            this.familyIndex = familyIndex;
            this.isGreenBuild = isBoolean(isGreenBuilding);
            uni.$check_and_login(this.initPage)
        },
        methods:{
            //初始化
            initPage() {
                //[0,1] 0:默认额度 1:绿色建筑额度
                let obj = {
                    personal: {
                        first: [80, 92],
                        other: [65, 74.75]
                    },
                    family: {
                        first: [160, 184],
                        other: [130, 149.5]
                    },
                    multChildren: {
                        first: [192, 216],
                        other: [130, 149.5]
                    }
                }
                const houssNum = this.houseIndex === '0' ? 'first':'other';
                const familyType = this.familyIndex === '0' ? 'personal': (this.familyIndex === '1' ? 'family' : 'multChildren')
                //如果是绿色建筑，则贷款额度计算结果
                if(this.isGreenBuild) {
                    this.loanAmount = obj[familyType][houssNum][1]
                }else{
                    this.loanAmount = obj[familyType][houssNum][0]
                }
            },

            againCalc(){
                uni.navigateBack({
                    delta: 1
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    .page{
        padding: 30rpx;
        min-height: 100vh;
        overflow: hidden;
        line-height: 1;
        .item{
            padding: 30rpx 0rpx;
            justify-content: space-between;
            border-bottom: 1rpx solid rgba(0,0,0,.05);
        }
        .submitBtn{
            height: 80rpx;
            line-height: 80rpx;
            border-radius: 10rpx;
            margin-top: 70rpx;
            text-align: center;
        }
        .tips{
            margin-top: 40rpx;
            line-height: 1.5;
        }
    }
</style>
